private class EventLogsManagerController.ParserContentHandler extends DefaultHandler
DefaultHandler
for creating
a specific content handler for the SAXParser
object.
It will be used by the parser to manage SAXParseException
exceptions that may occur during the parsing of the EventLogEditor
content
(validateEventLog()
method).
This class will log into a StringBuffer
object warnings and errors
that may occur during the parsing and stop the entire parsing process if a fatal error
occurs, throwing a SAXException
.
DefaultHandler
,
SAXParser
,
SAXParseException
,
SAXException
,
EventLogEditor
,
StringBuffer
Modifier and Type | Field and Description |
---|---|
private String |
element
This variable records the element name of the block that
the parser is checking at a certain moment of the process.
|
private boolean |
isValid
This variable records if an error occurred during the parsing or not.
|
private String |
newline
The system line separator
|
private StringBuffer |
parserLog
This variable records warnings and errors from the parsing process.
|
Constructor and Description |
---|
ParserContentHandler()
Creates a new
ParserContentHandler , calling the
superclass constructor and then initialising the class variables. |
Modifier and Type | Method and Description |
---|---|
private void |
addInfo(StringBuffer message,
SAXParseException exception)
This method reads the line number, column number and message of the passed
SAXParseException and then append this information to the passed
StringBuffer . |
void |
error(SAXParseException exception)
Receive notification of a recoverable parser error.
|
void |
fatalError(SAXParseException exception)
Report a fatal XML parsing error.
|
StringBuffer |
getParserLog()
This method returns the
StringBuffer parserLog
that contains the log of the parsing process. |
boolean |
isDocumentValid()
This method returns the value of the
isValid variable. |
void |
startElement(String uri,
String localName,
String qName,
Attributes attributes)
Receive notification of the start of an element.
|
void |
warning(SAXParseException exception)
Receive notification of a parser warning.
|
characters, endDocument, endElement, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl
private String element
If a SAXParseException
occurs, this is the
element name of the block that generates the exception.
SAXParseException
private String newline
private StringBuffer parserLog
StringBuffer
private boolean isValid
If true
, nothing happened or at least one or more warnings have
been generated; if false
, at least one error or a fatal error have
been generated.
public ParserContentHandler()
ParserContentHandler
, calling the
superclass constructor and then initialising the class variables.public StringBuffer getParserLog()
StringBuffer
parserLog
that contains the log of the parsing process.parserLog
component.public boolean isDocumentValid()
isValid
variable.
that records if an error occurred during the parsing or not.isValid
variable.public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
When the parser start to process a new element, this method sets the
the element
variable with the value of the parameter localName
if this is not null or empty, with the value of the parameter qName
otherwise.
On this way, the element
variable will always contain the name of the element
that the parser is processing in a certain moment.
startElement
in interface ContentHandler
startElement
in class DefaultHandler
uri
- the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performedlocalName
- the local name (without prefix), or the empty string if Namespace processing is not being performedqName
- the qualified name (with prefix), or the empty string if qualified names are not availableattributes
- the attributes attached to the element. If there are no attributes, it shall be an empty Attributes objectSAXException
- any SAX exception, possibly wrapping another exceptionSAXException
public void warning(SAXParseException exception) throws SAXException
The method appends to the parserLog
the warning information,
with details like the element that was processed when the exception occurred,
the line number, the column number and the warning message.
warning
in interface ErrorHandler
warning
in class DefaultHandler
exception
- the warning information encoded as an exceptionSAXException
- this method takes and manages the exception received and does not throw it to the callerSAXParseException
,
SAXException
public void error(SAXParseException exception) throws SAXException
The method appends to the parserLog
the error information,
with details like the element that was processed when the exception occurred,
the line number, the column number and the error message.
error
in interface ErrorHandler
error
in class DefaultHandler
exception
- the error information encoded as an exceptionSAXException
- this method takes and manages the exception received and does not throw it to the callerSAXParseException
,
SAXException
public void fatalError(SAXParseException exception) throws SAXException
The method asks to the View to show an Error dialog with the error information in it
and then throws a SAXParseException
to tell to the caller method that it has to stop.
fatalError
in interface ErrorHandler
fatalError
in class DefaultHandler
exception
- the error information encoded as an exceptionSAXException
- this method takes and manages the exception received and then throws it to the callerSAXParseException
,
SAXException
private void addInfo(StringBuffer message, SAXParseException exception)
SAXParseException
and then append this information to the passed
StringBuffer
.message
- the StringBuffer
where to append the informationexception
- the SAXParseException
where to read the informationStringBuffer
,
SAXParseException